package org.roger.almeida.client.view;

import org.roger.almeida.client.AppEvents;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.View;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HtmlContainer;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.AccordionLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;

public class DashBoardView extends View {

	private ContentPanel west;

	public DashBoardView(Controller controller) {
		super(controller);
	}

	@Override
	protected void handleEvent(AppEvent event) {
		if(event.getType()== AppEvents.INIT){
			initUi();
		}
	}
	
	private void initUi(){
		Viewport viewport = new Viewport();
		viewport.setLayout(new BorderLayout());
		
		createNorth(viewport);
		createWest(viewport);
		createCenter(viewport);
	}

	private void createCenter(Viewport viewport) {
		LayoutContainer center = new LayoutContainer();
	    center.setLayout(new FitLayout());

	    BorderLayoutData data = new BorderLayoutData(LayoutRegion.CENTER);
	    data.setMargins(new Margins(5, 5, 5, 5));

	    viewport.add(center, data);
	}

	private void createWest(Viewport viewport) {
		BorderLayoutData data = new BorderLayoutData(LayoutRegion.WEST, 200, 150, 350);
	    data.setMargins(new Margins(5, 0, 5, 5));

	    west = new ContentPanel();
	    west.setBodyBorder(false);
	    west.setLayout(new AccordionLayout());
	    west.setLayoutOnChange(true);
	    west.setHeading("Almeida");

	    viewport.add(west, data);
	}

	private void createNorth(Viewport viewport) {
		HtmlContainer htmlContainer = new HtmlContainer();
		htmlContainer.setStateful(false);
		
		BorderLayoutData borderLayoutData = new BorderLayoutData(LayoutRegion.NORTH, 33);
		borderLayoutData.setMargins(new Margins());
		
		viewport.add(htmlContainer, borderLayoutData);
	}

}
